using Microsoft.AspNetCore.Mvc;
using System.Diagnostics;
using System.Threading.Tasks;
using WebApplication1.Models;

namespace WebApplication1.Controllers
{
    public class HomeController : Controller
    {
        private readonly ILogger<HomeController> _logger;
        private readonly MyHttp _myHttp;
        public HomeController(ILogger<HomeController> logger, MyHttp myHttp)
        {
            _logger = logger;
            _myHttp = myHttp;
        }
        //https://learn.microsoft.com/zh-cn/dotnet/core/extensions/httpclient-factory#avoid-typed-clients-in-singleton-services
        public async Task<IActionResult> Index()
        {
            //for (int i = 0; i < 1000; i++)
            //{
            //    var res = await _myHttp.GetAsync("https://www.baidu.com");
            //}
            //Console.WriteLine(res.Substring(0,100));
            return View();
        }

        public IActionResult Privacy()
        {
            return View();
        }

        [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
        public IActionResult Error()
        {
            return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
        }
    }
}
